Skip to content

Add bidirectional form communication API for dashboard apps#453

Merged
lkostrowski merged 20 commits intomainfrom
ENG-456-form-comms
Oct 30, 2025
Merged

Add bidirectional form communication API for dashboard apps#453
lkostrowski merged 20 commits intomainfrom
ENG-456-form-comms

Conversation

@lkostrowski
Copy link
Copy Markdown
Member

@lkostrowski lkostrowski commented Sep 25, 2025

Summary

This PR introduces a new experimental API for bidirectional communication between Saleor dashboard forms and apps. This enables apps to receive form context and update form fields programmatically.

Key Features

New Form Communication API

  • Form Payload Event: Apps can now receive form data through the formPayload event, including current field values, metadata, and form context
  • Form Update Action: Apps can update form fields using the formPayloadUpdate action, allowing them to:
    • Set field values
    • Control popup closure behavior
    • Selectively update only the fields they need (fields parameter is optional)

Supported Forms

  • Product Edit: Access and update product name and description fields
  • Product Translate: Access and update translated content including product name, description, and SEO fields with translation context (original, translated, and current values)

Type-Safe Implementation

  • Strongly typed payloads for each form type
  • Discriminated unions for type safety
  • Support for different field types (short-text, editorjs)

Technical Changes

New Files

  • src/app-bridge/form-payload.ts: Core types and constants for form communication

Modified Files

  • src/app-bridge/actions.ts: Added FormPayloadUpdate action
  • src/app-bridge/events.ts: Added FormDataEvent for form payload
  • src/app-bridge/app-bridge-state.ts: Updated state management
  • Various test files with comprehensive coverage
  • Platform adapter updates for type compatibility

Example Usage

// Receive form data
appBridge.subscribe("formPayload", (payload) => {
  if (payload.form === "product-translate") {
    const { productName, productDescription } = payload.fields;
    // Process translation data
  }
});

// Update form fields (fields parameter is optional - only update what you need)
appBridge.dispatch(
  actions.FormPayloadUpdate({
    form: "product-translate",
    fields: {
      productName: { value: "Translated name" },
      productDescription: { value: "Translated description" }
    },
    closePopup: true
  })
);

Notes

This is an experimental API and may be subject to changes based on feedback and usage patterns.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Sep 25, 2025

🦋 Changeset detected

Latest commit: 6d7304a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@saleor/app-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 97.59036% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.98%. Comparing base (25a1603) to head (6d7304a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/APL/vercel-kv/vercel-kv-apl.ts 66.66% 1 Missing ⚠️
src/app-bridge/next/route-propagator.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #453      +/-   ##
==========================================
+ Coverage   84.84%   84.98%   +0.14%     
==========================================
  Files         114      115       +1     
  Lines        3754     3789      +35     
  Branches      637      640       +3     
==========================================
+ Hits         3185     3220      +35     
  Misses        557      557              
  Partials       12       12              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20250925064601.

Install it with:

pnpm add @saleor/[email protected]

@github-actions
Copy link
Copy Markdown
Contributor

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20250925102530.

Install it with:

pnpm add @saleor/[email protected]

@github-actions
Copy link
Copy Markdown
Contributor

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20251017090310.

Install it with:

pnpm add @saleor/[email protected]

@github-actions
Copy link
Copy Markdown
Contributor

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20251017115503.

Install it with:

pnpm add @saleor/[email protected]

@github-actions
Copy link
Copy Markdown
Contributor

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20251029095136.

Install it with:

pnpm add @saleor/[email protected]

@github-actions
Copy link
Copy Markdown
Contributor

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20251029114336.

Install it with:

pnpm add @saleor/[email protected]

@github-actions
Copy link
Copy Markdown
Contributor

Released snapshot build with @dev tag in npm with version: 0.0.0-pr-20251030070348.

Install it with:

pnpm add @saleor/[email protected]

@lkostrowski lkostrowski changed the title Add event for form communication Add bidirectional form communication API for dashboard apps Oct 30, 2025
@lkostrowski lkostrowski marked this pull request as ready for review October 30, 2025 10:26
Copy link
Copy Markdown
Member

@witoszekdev witoszekdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any comments for code itself, lgtm

I do have some proposal for the API though. As far as I understand, we will receive updates for all forms in dashboard inside the app? 🤔

appBridge.subscribe("formPayload", (payload) => {
  if (payload.form === "product-translate") {

I would probably add possibility to subscribe to only specific forms, or single form at a time, so that we don't have handlers that listen to only one form, but get events for all of them.

@lkostrowski
Copy link
Copy Markdown
Member Author

I don't have any comments for code itself, lgtm

I would probably add possibility to subscribe to only specific forms, or single form at a time, so that we don't have handlers that listen to only one form, but get events for all of them.

It's likely not possible because app is mounted on the single context, so you have sinlge form. You can't have open app that is listening to translate product and edit product, because they are different views

@lkostrowski lkostrowski merged commit 0dad90f into main Oct 30, 2025
9 checks passed
@lkostrowski lkostrowski deleted the ENG-456-form-comms branch October 30, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants